<?php
/*************************
  Coppermine Photo Gallery
  ************************
  Copyright (c) 2003-2005 Coppermine Dev Team
  v1.1 originaly written by Gregory DEMAR

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.
  ********************************************
  Coppermine version: 1.4.6
  $Revision: 2.1 $
  $Author: TranzNDance $
  $Date: 2006/05/31 $
  
  ************************
    Mod: Coppermine files mapped on Google Maps
	Demo: http://TakeThu.com Location Map
**********************************************/
define('IN_COPPERMINE', true);
define('GMAP_PHP', true);
define('DISPLAYIMAGE_PHP', true);
define('REGISTER_PHP', true);
define('SEARCH_PHP', true);

require('include/init.inc.php');

$album = $_GET['album'];
pageheader($lang_gmap_php['title']);

if ($CONFIG['enable_smilies']) include("include/smilies.inc.php");

$map_key = $CONFIG['gmap_api_key'];
$default_zoom_level = $CONFIG['gmap_default_zoom'];
$title = $lang_gmap_php['title'];
if ($CONFIG['gmap_display_item_list'] == 1) {
	$show_sidebar = TRUE;
}
if ($CONFIG['gmap_override_avg_coord'] == 0 || $CONFIG['gmap_default_center'] == NULL) {
	$center_avg_coords = TRUE;
}

//for the album drop down menu
//get the url and all vars except $theme
$cpgCurrentAlbum = $_SERVER["SCRIPT_NAME"]."?";
foreach ($_GET as $key => $value) {
    if ($key!="album"){$cpgCurrentAlbum .= $key . "=" . $value . "&amp;";}
}
$cpgCurrentAlbum.="album=";
if(count($FORBIDDEN_SET_DATA) > 0 ){
    $forbidden_set_string =" AND albums.aid NOT IN (".implode(",", $FORBIDDEN_SET_DATA).")";
} else {
    $forbidden_set_string = '';
}

// get list of available albums
	$albums = implode(",",$album_array);

	$filter = "aid IN (" . $albums . ")";
	$query = "SELECT albums.*, pictures.*, albums.title AS title, COUNT(*) AS n
			FROM {$CONFIG['TABLE_ALBUMS']} AS albums, {$CONFIG['TABLE_PICTURES']} AS pictures
			WHERE 
			pictures.aid = albums.aid 
			AND ABS(pictures.latitude) + ABS(pictures.longitude) > 0
			$query $forbidden_set_string
			GROUP BY albums.aid
			ORDER BY albums.title
			;";

$result = cpg_db_query($query);

//start the output
switch ($parameter) {
   case 'table':
       $return = 'not yet implemented';
       break;
   default:
       $return.= $lineBreak . '<form name="cpgChooseAlbum" action="' . $_SERVER['PHP_SELF'] . '" method="get" style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;display:inline">' . $lineBreak;
       $return.= '<select name="cpgThemeSelect" class="listbox_lang" onchange="if (this.options[this.selectedIndex].value) window.location.href=\'' . $cpgCurrentAlbum . '\' + this.options[this.selectedIndex].value;">' . $lineBreak;
       $return.='<option selected="selected">' . $lang_main_menu['alb_list_lnk'] . '</option>';
	$count = 0; 
while($row = mysql_fetch_array($result))
{
$aid = $row['aid'];
$album_title = addslashes($row['title']);
	// title string: If there is no title, use the number
	if (strlen($row['title']) > 0) {
		$album_title = $row['title'];
	} else {
		$album_title = 'Album: ' . $aid;
	}
	$return.= '<option value="' . $aid . '">' . $album_title . ' (' . $row['n'] . ')' . ($value == $aid ? '*' : ''). '</option>' . $lineBreak;
	$count = $count + $row['n'];
}
          if ($CONFIG['theme_reset'] == 1){
              $return.=  '<option value="*">' . $lang_gmap_php['all_albums'] . ' (' . $count . ')' . '</option>' . $lineBreak;
          }
          $return.=  '</select>' . $lineBreak;
          $return.=  '</form>' . $lineBreak;
   }

include('include/map.inc.php');
pagefooter(); 
?>